﻿@using Orchard.DisplayManagement.Shapes
@using Orchard.DynamicForms.Elements
@using Orchard.Layouts.Helpers
@{
    var element = (EmailField)Model.Element;
    var tagBuilder = (OrchardTagBuilder)TagBuilderExtensions.CreateElementTagBuilder(Model, "input");

    tagBuilder.AddCssClass("text");
    tagBuilder.Attributes["type"] = "email";
    tagBuilder.Attributes["value"] = Model.ProcessedValue;
    tagBuilder.Attributes["name"] = Model.ProcessedName;
    tagBuilder.AddClientValidationAttributes((IDictionary<string, string>)Model.ClientValidationAttributes);

    if (!ViewData.ModelState.IsValidField(Model.ProcessedName)) {
        tagBuilder.AddCssClass("input-validation-error");
    }
}

@if (element.ShowLabel) {
    <label for="@element.HtmlId">@Model.ProcessedLabel</label>
}
@tagBuilder.ToHtmlString(TagRenderMode.SelfClosing)
@if (element.ValidationSettings.ShowValidationMessage == true) {
    @Html.ValidationMessage((string)Model.ProcessedName)
}